package com.ofek.applicationbase.forms.question;

import java.io.Serializable;

import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.ofek.applicationbase.R;
import com.ofek.applicationbase.forms.QuestionView;


public class CheckBoxQuestionView extends QuestionView {

	private CheckBox checkBox;
	public CheckBoxQuestionView(final int resourceId,final Context context) {
		super(R.layout.form_question_checkbox,context);
		init(resourceId);
	}
	public CheckBoxQuestionView(final int layoutId, final int resourceId,final Context context) {
		super(layoutId,context);
		init(resourceId);
	}
	private void init(final int res) {
		checkBox = (CheckBox)findViewById(R.id.checkbox);
		checkBox.setText(res);
		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
				broadcastAnswerChanged(isChecked);
			}
		});
	}
	
	
	@Override
	public Serializable getAnswer() {
		return checkBox.isChecked();
	}
	@Override
	public void setAnswer(final Object defaultAnswer) {
		checkBox.setChecked((Boolean)defaultAnswer);
	}
	@Override
	public void setEditable(final boolean edit) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void setDefaultAnswer(Object defaultAnswer, boolean shouldPrePick) {
		if (defaultAnswer!=null && shouldPrePick) 
			setAnswer(defaultAnswer);
	}
	
	
	
}
